package com.xiaohe66.web.gateway.http.love;

import com.xiaohe66.common.value.R;
import com.xiaohe66.web.application.love.DailyAppService;
import com.xiaohe66.web.application.love.bo.DailyListBo;
import com.xiaohe66.web.application.love.bo.DailySaveBo;
import com.xiaohe66.web.application.love.result.DailyResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiaohe
 * @since 2021.11.30 14:25
 */
@RestController
@RequestMapping("/love/daily")
@RequiredArgsConstructor
public class DailyController {

    private final DailyAppService dailyAppService;

    @PostMapping
    public R<DailyResult> save(@RequestBody DailySaveBo bo) {

        DailyResult result = dailyAppService.save(bo);

        return R.ok(result);
    }

    @DeleteMapping("/{id}")
    public R<Void> removeById(@PathVariable(value = "id") Long id) {

        dailyAppService.removeById(id);

        return R.ok();
    }

    @GetMapping
    public R<List<DailyResult>> list(DailyListBo bo) {

        List<DailyResult> list = dailyAppService.listByLoverId(bo);

        return R.ok(list);
    }

}
